/**
 * @Author: 雷◕‿◕宇
 * @Description: 初始化列表
 * @Date: 2018/10/29
 */
void main() {
  var person = new Person("Tom", 20, "Male");
  person.work();

  var p1 = Person.withMap({"name": "zs", "age": 18, "gender": "male"});
  p1.work();

  var p2 = Person.fromMap({"name": "zs"});
  p2.work();
}

class Person {
  String? name;
  int? age;

  final String gender;

  Person(this.name, this.age, this.gender);

  Person.fromMap(Map map) : gender = map["gender"] ?? 'male' {
    this.age = map['age'];
    this.name = map['name'];
  }

  Person.withMap(Map map)
      : name = map["name"],
        gender = map["gender"] {
    age = map["age"];
  }

  void work() {
    print("${name} ${age} ${gender} Work...");
  }
}
